package mygang.listener;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import mygang.model.BaseModel;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 */
public class SessionListener extends BaseModel implements HttpSessionListener {
    
    private static List<String> sessions = new ArrayList<String>();
    
    public SessionListener(){
    }
    
    public void sessionCreated(HttpSessionEvent hse) {
        sessions.add(hse.getSession().getId());
    }

    public void sessionDestroyed(HttpSessionEvent hse) {
        sessions.remove(hse.getSession().getId());
    }
    
    public static int getActiveSessionNumber() {
        return sessions.size();
    }
}
